<?php
class Front_Preauthorize_Generic extends System_Db_Generic  {
// evaluate as php
	public function getFund(){
		$db = Zend_Registry :: get("db");
		$statement = $db->prepare('exec dbo.sp_queryFundId');
		$statement->execute();
		$results = $statement->fetchAll();
		return $results;
	}
	public function getpreauthbyfund($params){
		$db = Zend_Registry :: get("db");
		switch ($params['searchby']){
			case 'policy':
				$cmd_exec = "exec dbo.sp_queryByPolicyNo ".$params['fund_id'].",'".$params['policy_no']."',NULL";
				break;
			case 'fname' || 'lname':
				$cmd_exec = "exec dbo.sp_queryByNameSname ".$params['fund_id'].",'".$params['fname']."','".$params['lname']."'";
				break;
			case 'flname':
				$cmd_exec = "exec dbo.sp_queryByPolicyNo ".$params['fund_id'].",'".$params['fname']."','".$params['lname']."'";
				break;
			default: return; break;
		}
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		foreach ($results as $key=>$value){
			$results[$key]['effective'] = getDateFormat($results[$key]['effective']);
			$results[$key]['expiry'] = getDateFormat($results[$key]['expiry']);
		}
		return $results;
	}
	public function getPreauthId(){
		$db = Zend_Registry :: get("db");
		$statement = $db->prepare('select dbo.FN_Preauth_GenID () as preauth_id');
		$statement->execute();
		$results = $statement->fetchAll();
		return $results['0']['preauth_id'];
	}
	public function getPolicyById($policy_id){
		if(!$policy_id) return;
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_queryByPolicyId '$policy_id'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		foreach ($results as $key=>$value){
			$results[$key]['effective'] = getDateFormat2($results[$key]['effective']);
			$results[$key]['expiry'] = getDateFormat2($results[$key]['expiry']);
			$results[$key]['me_cover'] = number_format($results[$key]['me_cover'],2,'.',',');
			$results[$key]['mc_cover'] = number_format($results[$key]['mc_cover'],2,'.',',');
		}
		return $results['0'];
	}
	public function getPaInfo($policy_id){
		if(!$policy_id) return;
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_policy_get_info '$policy_id'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		return $results['0'];
	}
	public function getPaClaim($policy_id){
		if(!$policy_id) return;
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_Claim_Get_PA_Claim '$policy_id'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		foreach ($results as $key=>$value){
			$results[$key]['acc_date'] = getDateFormat2($results[$key]['acc_date']);
			$results[$key]['paid'] = number_format($results[$key]['paid'],2,'.',',');
		}
		return $results;
	}
	public function getPaClaimOpd($policy_id){
		if(!$policy_id) return;
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_Claim_Get_HealthOPD_Claim '$policy_id'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		foreach ($results as $key=>$value){
			$results[$key]['acc_date'] = getDateFormat2($results[$key]['acc_date']);
			$results[$key]['paid'] = number_format($results[$key]['paid'],2,'.',',');
		}
		return $results;
	}
	public function getErClaim($policy_id){
		if(!$policy_id) return;
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_Claim_Get_ER_Claim '$policy_id'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		foreach ($results as $key=>$value){
			$results[$key]['acc_date'] = getDateFormat2($results[$key]['acc_date']);
			$results[$key]['paid'] = number_format($results[$key]['paid'],2,'.',',');
		}
		return $results;
	}
	public function getPlan2catByPlanId($plan_id){
		if(!$plan_id) return;
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_getPlan2catByPlanid '$plan_id'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		return $results['0'];
	}
	public function insertPreauth($params){
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_Preauth_Trans_Save '".$params['preauth_id']."','".$params['user_id']."','".$params['policy_no']."','".$params['policy_id']."','".$params['preauth_datetime']."',NULL,'".$params['customer_type_desc']."'";
		$statement = $db->prepare($cmd_exec);
		$results = $statement->execute();
		return $results;
	}
	public function getpreauthbyidcard($params){
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_queryByNatID ".$params['fund_id'].",'".$params['nat_id']."'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		foreach ($results as $key=>$value){
			$results[$key]['effective'] = getDateFormat($results[$key]['effective']);
			$results[$key]['expiry'] = getDateFormat($results[$key]['expiry']);
		}
		return $results;
	}
}
?>